<%--
  Created by IntelliJ IDEA.
  User: SXT
  Date: 2020/6/24
  Time: 15:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>主持人管理页面</title>
    <base href="<%=request.getContextPath()+"/"%>">
    <%--引入easyui主题的css样式--%>
    <link rel="stylesheet" href="easyui/themes/default/easyui.css">
    <%--引入easyui中图标集的css样式--%>
    <link rel="stylesheet" href="easyui/themes/icon.css">
    <%--引入demo.css--%>
    <link rel="stylesheet" href="easyui/themes/demo.css">
    <%--引入jq中js文件  注意：先引入jq中js在引入easyui中js--%>
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <%--引入easyui中核心js文件--%>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>

    <script type="text/javascript">

         $(function () {
             $('#dg').datagrid({
                 url: 'HostController/findHosts',
                 pagination: true,//设置分页栏展示
                 //rownumbers:true,//设置行号显示
                 pageSize: 5,//设置size的初始大小
                 pageList: [5, 10, 15, 20],// 设置每一页显示条数列表
                 toolbar: "#tb",
                 columns: [[

                     {field: 'strong', title: '权重', width: 70, align: 'center',
                         formatter: function(value,row,index){
                             return  "<input onblur='changeStrong(this.value,"+row.hid+")' type='text' value='"+value+"' style='width: 40px'/>";
                         }},
                     {field: 'hname', title: '姓名', width: 70, align: 'center'},
                     {field: 'hphone', title: '手机号', width: 70, align: 'center'},
                     {field: 'starttime', title: '开通时间', width: 70, align: 'center',
                         formatter: function(value,row,index){
                             return  value.year+"-"+value.monthValue+"-"+value.dayOfMonth;
                         }},
                     {field: 'hpprice', title: '价格', width: 70, align: 'center',
                         formatter: function(value,row,index){
                             return  row.hostPower.hpprice==null?"新人暂无":row.hostPower.hpprice;
                         }},
                     {field: 'num', title: '订单量', width: 70, align: 'center'},
                     {field: 'discount', title: '折扣', width: 70, align: 'center',
                         formatter: function(value,row,index){
                             return  row.hostPower.hpdiscount==null?"新人暂无":row.hostPower.hpdiscount;
                         }},
                     {field: 'xing', title: '星推荐', width: 70, align: 'center',
                         formatter: function(value,row,index){
                             return  row.hostPower.hpstart==null?"新人暂无":row.hostPower.hpstart;
                         }},
                     {field: 'status', title: '账号状态', width: 70, align: 'center'}
                 ]]
             });
             
             $("#btn1").click(function () {
                 //重新加载数据网格能够携带数据,但是只能是json格式的,因此无法用表格序列化得到数据
                 //要用序列化数组
                 var arr = $("#fm1").serializeArray();
                 //定义一个空的jason对象
                 var json={};
                 for (var i in arr){
                     //把数组中的内容取出放到json里,尼玛这怎么能这样写呢
                    json[arr[i].name]=arr[i].value;
             }
                 $("#dg").datagrid("load",json);
             })
         })
        
         function changeStrong(strong, hid) {
            $.post("HostController/changeHostStrongLer",{strong:strong,hid:hid},function (result) {
                if (result>0){
                    $("#dg").datagrid("reload");
                }else {
                    $.messager.alert("错误","修改失败","error");
                }
            })
        }

         function newzhc() {
             //打开对话框
             $("#dlg").dialog("open").dialog("setTital","NEW ZHC");
             //清空之前的数据残留
             $("#fm").form("clear");
         }

         function savezhr() {
             $.post("HostController/addHostLer",$("#fm").serialize(),function (result) {
                 if (result>0){
                     //关闭对话框
                     $("#dlg").dialog("close");
                     //重新加载数据网格
                     $("#dg").datagrid("reload");
                 }else(
                     $.messager.alert("错误","添加失败","error")
                 )
             })
         }

         var hids="";
         function zcrStatus() {
             var arr=$("#dg").datagrid("getSelections");
             if (arr.length>0){
                 //打开对话框
                 $("#zcrStatus_dlg").dialog("open").dialog("setTitle","Change State");
                 //清空表单的残留数据
                 $("#zcrStatus_fm").form("clear");
                 for (var i in arr){
                     if (hids!="") hids+=",";
                     hids+=arr[i].hid;
                 }
             }else {
                 $.messager.alert("提示","请先去选中需要修改的数据","info")
             }
         }

         function saveZcrStastus() {
             $.post("HostController/changeHostStatusLer?hids="+hids,$("#zcrStatus_fm").serialize(),function (result) {
                 if (result>0){
                     //关闭对话框
                     $("#zcrStatus_dlg").dialog("close");
                     //重新加载数据网格
                     $("#dg").datagrid("reload");
                     //清空hids的记录
                     hids="";
                 }else {
                     $.messager.alert("错误","状态修改失败","error");
                 }
             })
         }

         var hostids="";

         function zcrRoleB() {
             var arr2 = $("#dg").datagrid("getSelections");
             console.log(arr2);
             if (arr2.length>0){
                 //打开对话框
                 $("#zcr_dlg").dialog("open").dialog("setTitle","Save ZCR");
                 //清空表单的残留数据
                 $("#zcr_fm").form("load");
                 for (var i in arr2){
                     if (hostids!="") hostids+=",";
                     hostids+=arr2[i].hid;
                 }
                 console.log(hostids);
             }else {
                 $.messager.alert("提示",'请先选择需要权限修改信息的主持人',"info");
             }
         }

         function saveZcrRole() {
             $.post("hostPower/updateHostPowerLer?hostids="+hostids,$("#zcr_fm").serialize(),function (result) {
                 if (result>0){
                     //关闭对话框
                     $("#zcr_dlg").dialog("close");
                     //重新加载数据网格
                     $("#dg").datagrid("reload");
                     //清空hostid的残留记录
                     hostids="";
                 }else {
                     $.messager.alert("错误","权限修改失败","error");
                 }
             })
         }
    </script>
</head>
<body>

   <div style="width: 800px;height: 600px" class="easyui-panel" title="主持人管理">

             <%--顶部搜索框--%>
             <div style="width: 750px;height: 40px;border: 0px solid red;margin: 0px auto;margin-top: 30px">

                 <form id="fm1">
                     <input class="easyui-textbox" name="hname" data-options="prompt:'姓名'" style="width:100px">
                     <select id="cc" class="easyui-combobox" name="status" style="width:110px;">
                             <option value="">账号状态</option>
                             <option value="正常">正常</option>
                             <option value="禁用">禁用</option>
                     </select>
                     <select id="cc2" class="easyui-combobox" name="strong" style="width:110px;">
                         <option value="">权重排序</option>
                         <option value="asc">升序</option>
                         <option value="desc">降序</option>
                     </select>
                     <select id="cc3" class="easyui-combobox" name="hostPower.hpstart" style="width:110px;">
                         <option value="">星推荐</option>
                         <option value="是">是</option>
                         <option value="否">否</option>
                     </select>
                     <select id="cc4" class="easyui-combobox" name="hostPower.hpdiscount" style="width:110px;">
                         <option value="0">折扣</option>
                         <option value="6">六折</option>
                         <option value="7">七折</option>
                         <option value="8">八折</option>
                         <option value="9">九折</option>
                     </select>

                     <a id="btn1" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="margin-left: 30px">查询</a>

                     <a id="btn2" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">导出</a>
                 </form>

             </div>
              <%--底部信息展示位置--%>
              <div style="width: 750px;height: 400px;border: 0px solid red;margin: 0px auto;margin-top: 30px">

                  <table id="dg" style="width: 750px;height: 400px"></table>

                  <%--工具栏设置--%>
                  <div id="tb">
                      <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newzhc()">添加主持人</a>
                      <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="zcrStatus()">账号状态</a>
                      <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="zcrRoleB()">权限批量操作</a>
                  </div>
              </div>
              <%--添加主持人信息对话框的展示--%>
             <div id="dlg" class="easyui-dialog" style="width:400px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
                     <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
                         <h3>User Information</h3>
                         <div style="margin-bottom:10px">
                             <input name="hname" class="easyui-textbox" required="true" label="主持人姓名:" style="width:100%">
                         </div>
                         <div style="margin-bottom:10px">
                             <input name="hpwd" class="easyui-textbox" required="true" label="主持人密码:" style="width:100%">
                         </div>
                         <div style="margin-bottom:10px">
                             <input name="hphone" class="easyui-textbox" required="true" label="主持人电话:" style="width:100%">
                         </div>
                     </form>
             </div>
             <div id="dlg-buttons">
                     <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="savezhr()" style="width:90px">Save</a>
                     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
             </div>


             <%--主持人授权的对话框的展示--%>
             <div id="zcr_dlg" class="easyui-dialog" style="width:600px" data-options="closed:true,modal:true,border:'thin',buttons:'#zcr_dlg-buttons'">
                 <form id="zcr_fm" method="post" novalidate style="margin:0;padding:20px 50px">
                     <h3>User Information</h3>
                     <div style="margin-bottom:10px">
                         是否星推荐
                         <input class="easyui-radiobutton" name="hpstart" value="是" label="是:">
                         <input class="easyui-radiobutton" name="hpstart" value="否" label="否:">
                     </div>
                     <div style="margin-bottom:10px">
                         星推荐日期
                         <input name="hpstartBeigindate" class="easyui-textbox"    style="width:35%">-

                         <input name="hpstartEnddate" class="easyui-textbox" style="width:35%">
                     </div>
                     <div style="margin-bottom:10px">
                         是否自添加
                         <input class="easyui-radiobutton" name="hpOrderPower" value="是" label="是:">
                         <input class="easyui-radiobutton" name="hpOrderPower" value="否" label="否:">
                     </div>
                     <div style="margin-bottom:10px">
                         星推荐时间
                         <input name="hpstartBegintime" class="easyui-textbox"   style="width:35%">-

                         <input name="hpstartEndtime" class="easyui-textbox" style="width:35%">
                     </div>
                     <div style="margin-bottom:10px">
                         折扣价值&nbsp;&nbsp;&nbsp;
                         <input name="hpdiscount" class="easyui-textbox"  style="width:73%">
                     </div>

                     <div style="margin-bottom:10px">
                         折扣时间&nbsp;&nbsp;&nbsp;
                         <input name="hpDisStarttime" class="easyui-textbox" style="width:35%">-

                         <input name="hpDisEndtime" class="easyui-textbox" style="width:35%">
                     </div>
                     <div style="margin-bottom:10px">
                         主持人价格
                         <input name="hpprice" class="easyui-textbox"   style="width:73%">
                     </div>
                     <div style="margin-bottom:10px">
                         平台管理费
                         <input name="hcosts" class="easyui-textbox"  style="width:73%">
                     </div>
                 </form>
             </div>
             <div id="zcr_dlg-buttons">
                 <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveZcrRole()" style="width:90px">Save</a>
                 <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
             </div>

             <%--主持人授权的对话框的展示--%>
             <div id="zcrStatus_dlg" class="easyui-dialog" style="width:450px" data-options="closed:true,modal:true,border:'thin',buttons:'#zcrStatus_dlg-buttons'">
                 <form id="zcrStatus_fm" method="post" novalidate style="margin:0;padding:20px 50px">
                     <h3>修改账号状态</h3>
                     <div style="margin-bottom:10px">
                         账号状态
                         <input class="easyui-radiobutton" name="status" value="正常" label="正常:">
                         <input class="easyui-radiobutton" name="status" value="禁用" label="禁用:">
                     </div>

                 </form>
             </div>
             <div id="zcrStatus_dlg-buttons">
                 <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveZcrStastus()" style="width:90px">Save</a>
                 <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
             </div>

   </div>

</body>
</html>
